<template>
  <view class="body flex-col">
    <view v-if="isShowTitle">
      <u-navbar :is-back="isBack" back-text=" " title="商品列表"></u-navbar>
    </view>
    <scroll-view @scrolltolower="loadData()" scroll-y class="list">
      <div class="list-box" v-if="pageData.list.length">
        <template v-for="(good, index) in pageData.list">
          <horizontalList :key="index" :good="good"></horizontalList>
        </template>
        <u-loadmore :status="status"></u-loadmore>
      </div>
      <u-empty v-else mode="data"></u-empty>
    </scroll-view>
  </view>
</template>

<script>
import horizontalList from '@/components/search/components/horizontalList.vue'; // 横版商品

export default {
  props: {
    isShowTitle: {
      type: Boolean,
      default: false,
    },
  },
  components: {
    horizontalList,
  },
  data() {
    return {
      pageData: {
        list: [],
        page: 1,
      },
      status: 'loadmore',
    };
  },
  created() {
    uni.setNavigationBarTitle({
      title: this.stores.name,
    });
    this.loadData();
  },
  methods: {
    async loadData(reset) {
      if (reset) {
        let { pageData, status } = this.$options.data();
        this.pageData = pageData;
        this.status = status;
      }
      if (this.status == 'nomore') return;
      const res = await this.$allrequest.search.getSearchList(
        {
          keyword: '',
          page: this.pageData.page,
        },
        true
      );
      this.pageData.list.push(...res.data.list);
      this.status =
        res.data.row_count <= this.pageData.list.length ? 'nomore' : 'loadmore';
      this.pageData.page++;
    },
  },
  computed: {
    // 是否显示返回箭头
    isBack() {
      var pages = getCurrentPages();
      return pages.length > 1;
    },
  },
};
</script>

<style lang="scss" scoped>
.body {
  height: 100vh;
  .list {
    height: 0;
    flex: 1;
    .list-box {
      padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
    }
  }
}
</style>
